<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/4/15
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>用户列表页</title>
  <%--<style>

    table{
         /*单元格空虚合并*/
         border-collapse: collapse;
         background-color: ivory;
    }


  </style>--%>
  <link href="${pageContext.request.contextPath}/css/bootstrap.min.css"  rel="stylesheet"/>
  <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
  <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
<div>

  <div style="float: left;margin-bottom: 5px;font-size: 20px;">
    <input type="button"  value="添加用户" class="btn btn-success" onclick="addUser()" />
  </div>
  <%--<table border="1px" align="center" width="100%" height="500px">--%>
   <table class="table table-hover table-bordered table-striped table-responsive">
    <tr>
      <th>用户编号</th>
      <th>用户昵称</th>
      <th>真实姓名</th>
      <th>用户邮箱</th>
      <th>用户性别</th>
      <th>用户操作</th>
    </tr>
    <%--<c:forEach items="${users}" var="u">--%>
     <c:forEach items="${pb.pageList}" var="u">
      <tr>
        <td>${u.uid}</td>
        <td>${u.username}</td>
        <td>${u.name}</td>
        <td>${u.email}</td>
        <td>${u.sex}</td>
        <td>
          <a href="javascript:void(0)" class="btn btn-warning" onclick="update('${u.uid}')" >修改</a>
          <a href="javascript:void(0)"  class="btn btn-danger" onclick="delUser('${u.uid}')">删除</a>
        </td>
      </tr>
    </c:forEach>

  </table>
</div>
<div style="float: right;margin-right: 10px;">
共有<span>${pb.totalPage}</span>页
共有<span>${pb.totalCount}</span>记录
</div>
<%--分页组件--%>
  <nav style="margin-left: 350px;" aria-label="Page navigation">
    <ul class="pagination">
      <!--上一页-->
      <%--判断是第一页--%>
      <c:if test="${pb.currentPage==1}">
        <%--bootstarp提供样式 class="disabled" 禁用状态--%>
        <li class="disabled">
          <a href="javascript:void(0)" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
          </a>
        </li>
      </c:if>
      <%--判断不是第一页--%>
      <c:if test="${pb.currentPage!=1}">

        <li>
          <a href="${pageContext.request.contextPath}/user?methodName=getAllUser&curPage=${pb.currentPage-1}&pSize=4" aria-label="Previous">
            <span aria-hidden="true">&laquo;</span>
          </a>
        </li>
      </c:if>



      <!--遍历分页页码

       -->
      <c:forEach begin="1" end="${pb.totalPage}" var="n">
        <%--判断如果是当前页--%>
          <c:if test="${pb.currentPage==n}">
            <%--bootstrap 样式 :class="active"激活状态--%>
            <li class="active">

             <a href="#">${n}</a>
            </li>
          </c:if>
        <%--判断如果不是当前页,分页查询--%>
        <c:if test="${pb.currentPage!=n}">

          <li>

            <a href="${pageContext.request.contextPath}/user?methodName=getAllUser&curPage=${n}&pSize=4">${n}</a>
          </li>
        </c:if>



      </c:forEach>

      <%--<li><a href="#">2</a></li>
      <li><a href="#">3</a></li>
      <li><a href="#">4</a></li>
      <li><a href="#">5</a></li>--%>
      <!--下一页-->
      <%--判断如果是最后一页--%>
      <c:if test="${pb.currentPage==pb.totalPage}">
        <li class="disabled">
          <a href="javascript:void(0)" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
          </a>
        </li>
      </c:if>

      <%--判断如果不是最后一页--%>
      <c:if test="${pb.currentPage!=pb.totalPage}">
        <li>
          <a href="${pageContext.request.contextPath}/user?methodName=getAllUser&curPage=${pb.currentPage+1}&pSize=4" aria-label="Next">
            <span aria-hidden="true">&raquo;</span>
          </a>
        </li>
      </c:if>

    </ul>
  </nav>

</body>
<script>
  function  delUser(uid){
   // alert(uid) ;
    //友情提示,确认提示框
   var flag =  window.confirm("您忍心删除吗?") ;
   if(flag){
     //alert("要删除了") ;
     window.location.href="${pageContext.request.contextPath}/user?methodName=delUser&uid="+uid ;
   }
  }



  function update(uid){
   // alert(uid) ;
    window.location.href="${pageContext.request.contextPath}/user?methodName=findUser&uid="+uid ;
  }
  function addUser(){
      window.location.href="${pageContext.request.contextPath}/admin/user/add_user.jsp";
  }
</script>
</html>

